
package sigec_ead.controle.chamado;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import sigec_ead.controle.ConexaoJDBC;
import sigec_ead.modelo.chamado.Sala;

/**
 *
 * @author Joeldson
 */
public class SalaDAO {
    private ArrayList<String> result;

        public Sala consultarSala(String nome) throws SQLException {

        PreparedStatement ps = null;
        Connection con = null;

        String sql = "SELECT * FROM sala WHERE nome = ?";

        try {
            con = ConexaoJDBC.getConexao();
            ps = con.prepareStatement(sql);
            ps.setString(1, nome);
            ResultSet rs = ps.executeQuery();
            Sala s = new Sala();
            if (rs.next()) {
                s.setId(rs.getInt("id"));
                s.setNome(rs.getString("nome"));
                return s;
            } else {
                return null;
            }
        } finally {
            ps.close();
            con.close();
        }
    }
        
      public List<String> salas() throws SQLException {

        PreparedStatement ps = null;
        Connection con = null;

        String sql = "SELECT * FROM sala where id!=0";

        try {
            con = ConexaoJDBC.getConexao();
            ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();

            result = new ArrayList<String>();
            result.add("");
            while (rs.next()) {
                result.add(rs.getString("nome"));
            }
        } finally {
            ps.close();
            con.close();
        }
        return result;
    }
}
